// 探索发现相关 Mock 数据

import type { ExpertCategory, HealthArticle, TrendingTopic, FeedItem } from '@/types/explore';
import type { ApiResponse } from '@/types/api';

// 模拟延迟
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

// 专家领域分类
const mockExpertCategories: ExpertCategory[] = [
  {
    id: 'nutrition',
    name: '营养膳食',
    icon: '🥗',
    color: '#67C23A',
    description: '科学饮食，健康生活',
    articleCount: 128
  },
  {
    id: 'mental',
    name: '心理健康',
    icon: '🧠',
    color: '#E6A23C',
    description: '关注心理，关爱自己',
    articleCount: 96
  },
  {
    id: 'exercise',
    name: '运动健身',
    icon: '💪',
    color: '#F56C6C',
    description: '科学运动，强健体魄',
    articleCount: 85
  },
  {
    id: 'cardiovascular',
    name: '心血管健康',
    icon: '❤️',
    color: '#F56C6C',
    description: '关注心脏，守护健康',
    articleCount: 112
  },
  {
    id: 'sleep',
    name: '睡眠管理',
    icon: '😴',
    color: '#909399',
    description: '改善睡眠，提升生活质量',
    articleCount: 73
  },
  {
    id: 'chronic',
    name: '慢性病管理',
    icon: '🏥',
    color: '#409EFF',
    description: '科学管理，控制病情',
    articleCount: 145
  }
];

// 健康文章
const mockHealthArticles: HealthArticle[] = [
  {
    id: 'article_001',
    title: '如何科学降低血压：从饮食到生活方式的全面指南',
    summary: '高血压是现代人常见的健康问题，本文将从饮食、运动、作息等多方面介绍科学降压的方法...',
    content: '详细内容...',
    author: '张医生',
    authorTitle: '心血管专家',
    category: 'cardiovascular',
    tags: ['高血压', '饮食', '运动'],
    readCount: 12580,
    likeCount: 856,
    publishTime: Date.now() - 86400000 * 3,
    coverImage: 'https://via.placeholder.com/400x200'
  },
  {
    id: 'article_002',
    title: '改善睡眠质量的10个科学方法',
    summary: '良好的睡眠对健康至关重要。研究表明，这些方法可以有效改善睡眠质量...',
    content: '详细内容...',
    author: '李医生',
    authorTitle: '睡眠医学专家',
    category: 'sleep',
    tags: ['睡眠', '健康', '生活方式'],
    readCount: 9840,
    likeCount: 645,
    publishTime: Date.now() - 86400000 * 5,
    coverImage: 'https://via.placeholder.com/400x200'
  },
  {
    id: 'article_003',
    title: '压力管理：如何应对现代生活的焦虑',
    summary: '现代生活节奏快，压力大。本文介绍了多种科学有效的压力管理方法...',
    content: '详细内容...',
    author: '王医生',
    authorTitle: '心理咨询师',
    category: 'mental',
    tags: ['压力', '焦虑', '心理健康'],
    readCount: 15230,
    likeCount: 1024,
    publishTime: Date.now() - 86400000 * 1,
    coverImage: 'https://via.placeholder.com/400x200'
  },
  {
    id: 'article_004',
    title: '地中海饮食：最健康的饮食方式之一',
    summary: '地中海饮食被公认为世界上最健康的饮食模式之一，让我们了解其核心原则...',
    content: '详细内容...',
    author: '赵医生',
    authorTitle: '营养科主任',
    category: 'nutrition',
    tags: ['饮食', '营养', '健康'],
    readCount: 8560,
    likeCount: 523,
    publishTime: Date.now() - 86400000 * 7,
    coverImage: 'https://via.placeholder.com/400x200'
  }
];

// 热门话题
const mockTrendingTopics: TrendingTopic[] = [
  {
    id: 'topic_001',
    title: '季节性流感预防',
    description: '随着天气转凉，如何有效预防季节性流感成为大家关注的焦点',
    discussionCount: 2845,
    icon: '🤧',
    trend: 'up'
  },
  {
    id: 'topic_002',
    title: '糖尿病饮食管理',
    description: '糖尿病患者的饮食控制和血糖管理技巧',
    discussionCount: 1952,
    icon: '🍭',
    trend: 'up'
  },
  {
    id: 'topic_003',
    title: '办公室久坐危害',
    description: '长时间久坐对健康的影响及改善方法',
    discussionCount: 1673,
    icon: '💺',
    trend: 'stable'
  },
  {
    id: 'topic_004',
    title: '健康减肥方法',
    description: '科学减重，避免反弹的有效策略',
    discussionCount: 3256,
    icon: '⚖️',
    trend: 'up'
  }
];

/**
 * Mock 获取专家领域分类
 */
export const mockGetExpertCategories = async (): Promise<ApiResponse<{ categories: ExpertCategory[] }>> => {
  await delay(500);
  
  return {
    code: 200,
    data: {
      categories: mockExpertCategories
    },
    message: '获取成功'
  };
};

/**
 * Mock 获取分类下的文章
 */
export const mockGetCategoryArticles = async (categoryId: string): Promise<ApiResponse<{ articles: HealthArticle[] }>> => {
  await delay(600);
  
  const filteredArticles = mockHealthArticles.filter(article => article.category === categoryId);
  
  return {
    code: 200,
    data: {
      articles: filteredArticles
    },
    message: '获取成功'
  };
};

/**
 * Mock 获取推荐信息流
 */
export const mockGetRecommendedFeed = async (): Promise<ApiResponse<{ feed: FeedItem[] }>> => {
  await delay(800);
  
  // 模拟个性化推荐
  const feed: FeedItem[] = mockHealthArticles.map((article, index) => ({
    id: `feed_${article.id}`,
    type: 'article' as const,
    data: article,
    reason: index % 2 === 0 ? '根据您的浏览历史推荐' : '热门推荐'
  }));
  
  return {
    code: 200,
    data: {
      feed
    },
    message: '获取成功'
  };
};

/**
 * Mock 获取热门话题
 */
export const mockGetTrendingTopics = async (): Promise<ApiResponse<{ topics: TrendingTopic[] }>> => {
  await delay(500);
  
  return {
    code: 200,
    data: {
      topics: mockTrendingTopics
    },
    message: '获取成功'
  };
};

/**
 * Mock 获取文章详情
 */
export const mockGetArticleDetail = async (articleId: string): Promise<ApiResponse<HealthArticle>> => {
  await delay(600);
  
  const article = mockHealthArticles.find(a => a.id === articleId);
  
  if (!article) {
    return {
      code: 404,
      data: null as any,
      message: '文章不存在'
    };
  }
  
  return {
    code: 200,
    data: article,
    message: '获取成功'
  };
};